package queue;

/**
 * Created with IntelliJ IDEA.
 * Description：
 * User：user
 * DATE:2021-11-02
 * Time:16:13
 */
public class MyQueue {
    static  class  Node{
        public int val;
        public Node next;
        public Node(int val){
            this.val = val;
        }
    }
    public  Node first;
    public Node last;

    //尾插法
    public  void offer(int val){
        Node node = new Node(val);
        if(this.first == null){
            this.first = node;
            this.last = node;
        }else{
            this.last.next = node;
            this.last = node;
        }
    }

    //出队
    public int poll(){
        if(isEmpty()){
            throw  new RuntimeException("队列为空");
        }
        int val = this.first.val;
        this.first = this.first.next;
        return val;
    }

    public  boolean isEmpty(){
        return this.first == null;
    }

    public int peek(){
        if(isEmpty()){
            throw  new RuntimeException("队列为空");
        }
        return this.first.val;
    }

}
